﻿using System;
using System.Text;

namespace Poly2Tri
{
	// Token: 0x020003E8 RID: 1000
	public class AdvancingFront
	{
		// Token: 0x06001B48 RID: 6984 RVA: 0x000ACC3F File Offset: 0x000AAE3F
		public AdvancingFront(AdvancingFrontNode head, AdvancingFrontNode tail)
		{
			this.Head = head;
			this.Tail = tail;
			this.Search = head;
			this.AddNode(head);
			this.AddNode(tail);
		}

		// Token: 0x06001B49 RID: 6985 RVA: 0x00002973 File Offset: 0x00000B73
		public void AddNode(AdvancingFrontNode node)
		{
		}

		// Token: 0x06001B4A RID: 6986 RVA: 0x00002973 File Offset: 0x00000B73
		public void RemoveNode(AdvancingFrontNode node)
		{
		}

		// Token: 0x06001B4B RID: 6987 RVA: 0x000ACC6C File Offset: 0x000AAE6C
		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			for (AdvancingFrontNode advancingFrontNode = this.Head; advancingFrontNode != this.Tail; advancingFrontNode = advancingFrontNode.Next)
			{
				stringBuilder.Append(advancingFrontNode.Point.X).Append("->");
			}
			stringBuilder.Append(this.Tail.Point.X);
			return stringBuilder.ToString();
		}

		// Token: 0x06001B4C RID: 6988 RVA: 0x000ACCD7 File Offset: 0x000AAED7
		private AdvancingFrontNode FindSearchNode(double x)
		{
			return this.Search;
		}

		// Token: 0x06001B4D RID: 6989 RVA: 0x000ACCDF File Offset: 0x000AAEDF
		public AdvancingFrontNode LocateNode(TriangulationPoint point)
		{
			return this.LocateNode(point.X);
		}

		// Token: 0x06001B4E RID: 6990 RVA: 0x000ACCF0 File Offset: 0x000AAEF0
		private AdvancingFrontNode LocateNode(double x)
		{
			AdvancingFrontNode advancingFrontNode = this.FindSearchNode(x);
			if (x < advancingFrontNode.Value)
			{
				while ((advancingFrontNode = advancingFrontNode.Prev) != null)
				{
					if (x >= advancingFrontNode.Value)
					{
						this.Search = advancingFrontNode;
						return advancingFrontNode;
					}
				}
			}
			else
			{
				while ((advancingFrontNode = advancingFrontNode.Next) != null)
				{
					if (x < advancingFrontNode.Value)
					{
						this.Search = advancingFrontNode.Prev;
						return advancingFrontNode.Prev;
					}
				}
			}
			return null;
		}

		// Token: 0x06001B4F RID: 6991 RVA: 0x000ACD70 File Offset: 0x000AAF70
		public AdvancingFrontNode LocatePoint(TriangulationPoint point)
		{
			double x = point.X;
			AdvancingFrontNode advancingFrontNode = this.FindSearchNode(x);
			double x2 = advancingFrontNode.Point.X;
			if (x == x2)
			{
				if (point != advancingFrontNode.Point)
				{
					if (point == advancingFrontNode.Prev.Point)
					{
						advancingFrontNode = advancingFrontNode.Prev;
					}
					else
					{
						if (point != advancingFrontNode.Next.Point)
						{
							throw new Exception("Failed to find Node for given afront point");
						}
						advancingFrontNode = advancingFrontNode.Next;
					}
				}
			}
			else if (x < x2)
			{
				while ((advancingFrontNode = advancingFrontNode.Prev) != null)
				{
					if (point == advancingFrontNode.Point)
					{
						break;
					}
				}
			}
			else
			{
				while ((advancingFrontNode = advancingFrontNode.Next) != null)
				{
					if (point == advancingFrontNode.Point)
					{
						break;
					}
				}
			}
			this.Search = advancingFrontNode;
			return advancingFrontNode;
		}

		// Token: 0x04001D40 RID: 7488
		public AdvancingFrontNode Head;

		// Token: 0x04001D41 RID: 7489
		public AdvancingFrontNode Tail;

		// Token: 0x04001D42 RID: 7490
		protected AdvancingFrontNode Search;
	}
}
